﻿using System;
using System.Web;
using System.Web.UI;
using NazSoft.Framework.UsersManagement;
using NazSoft.Framework;

public partial class MyProfile : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            UserInfo user = new UserInfo();
            if (Request.QueryString["UserId"] != null)
                user = UserHelper.GetUserInfo(Convert.ToInt32(Request.QueryString["UserId"]));

            else
                user = System.Web.HttpContext.Current.Session["UserObj"] as UserInfo;

            txtEmailAddress.Text = user.Email;
            txtFirstName.Text = user.FirstName;
            txtLastName.Text = user.LastName;
            txtPassword.Text = user.Password;
            txtConfirmPass.Text = user.Password;
            txtPassword.Attributes.Add("value", user.Password);
            txtConfirmPass.Attributes.Add("value", user.Password);
            txtDesignation.Text = user.Designation;
            txtCellNumber.Text = user.CellNumber;
            txtUserName.Text = user.Username;
        }
    }
    protected void btnProfileUpdate_Click(object sender, EventArgs e)
    {
        UserInfo user = new UserInfo();

        //UserInfo user1 = System.Web.HttpContext.Current.Session["UserObj"] as UserInfo;
        UserInfo user1 = new UserInfo();
        if (Request.QueryString["UserId"] != null)
            user1 = UserHelper.GetUserInfo(Convert.ToInt32(Request.QueryString["UserId"]));
        else
            user1 = HttpContext.Current.Session["UserObj"] as UserInfo;

        user.CreatedDate = DateTime.Parse(DatetimeUtility.GetCurrentDateTime().ToShortDateString());
        //TextBox txtEmailAddress = LoginView1.FindControl("txtEmailAddress") as TextBox;
        //TextBox txtFirstName = LoginView1.FindControl("txtFirstName") as TextBox;
        //TextBox txtLastName = LoginView1.FindControl("txtLastName") as TextBox;
        //TextBox txtPassword = LoginView1.FindControl("txtPassword") as TextBox;
        //TextBox txtDesignation = LoginView1.FindControl("txtDesignation") as TextBox;
        //TextBox txtCellNumber = LoginView1.FindControl("txtCellNumber") as TextBox;
        //TextBox txtUserName = LoginView1.FindControl("txtUserName") as TextBox;

        user.UserId = user1.UserId;
        user.Username = user1.Username;

        user.Email = txtEmailAddress.Text;
        user.FirstName = txtFirstName.Text;
        user.LastName = txtLastName.Text;
        if (txtPassword.Text != "")
            user.Password = txtPassword.Text;

        user.Designation = txtDesignation.Text;
        user.CellNumber = txtCellNumber.Text;
        user.Username = txtUserName.Text;

        int i = UserHelper.CreateUserAccount(user);
        if (Request.QueryString["UserId"] == null)
        {
            UserHelper.GetUserInfo(user1.Username, txtPassword.Text);
        }
        Response.Redirect("RegistrationThanks.aspx?Mode=ll", true);


    }

}
